<template>
  
  <div class="content">
    <div class="gov-sub1">
      <div>
        <div class="gov-box">
          <div class="gov-title">
            <p>行政中心用电负荷分布<i class="gl"></i><i class="gl"></i></p>
          </div>
          <div class="gov-sub1-top">
            <div class="gov-sub1-top-info">
              <div class="gov-box">
                <div>
                  <h3>{{ curentLoad.time }}</h3>
                  <h2>本时段用电总负荷</h2>
                </div>
                <div>
                  <span class="gov-num" v-for="item in (curentLoad.load+'')" :key="item.index">{{item}}</span>
                  <span class="gov-unit">KW</span>
                </div>
                <div>
                  <img :src="selectImg(curentLoad.rate)" >
                  <span>{{curentLoad.rate}}（相对于上一时段）</span>
                </div>
              </div>
              <div class="gov-box">
                <div class="gov-sub1-top-info-sub">
                  <div>
                    <h4>昨日用电量</h4>
                    <div>
                      <span class="gov-num" v-for="item in (yesterdayElecConsum.consum+'')" :key="item.index">{{item}}</span>
                      <span class="gov-unit">KW</span>
                    </div>
                  </div>
                  <div>
                    <img src="~@/assets/up.png" >
                    <span>5%（相对于上一时段）</span>
                  </div>
                </div>
                <div class="gov-sub1-top-info-sub">
                  <div>
                    <h4>昨日用水量</h4>
                    <div>
                      <span class="gov-num" v-for="item in  (yesterdayWaterConsum.flow+'')" :key="item.index">{{item}}</span>
                      <span class="gov-unit">吨</span>
                    </div>
                  </div>
                  <div>
                    <img src="~@/assets/down.png" >
                    <span>5%（相对于上一时段）</span>
                  </div>
                </div>
                <div class="gov-sub1-top-info-sub">
                  <div>
                    <h4>昨日蒸汽消耗量</h4>
                    <div>
                      <span class="gov-num" v-for="item in '1254'" :key="item.index">{{item}}</span>
                      <span class="gov-unit">m³</span>
                    </div>
                  </div>
                  <div>
                    <img src="~@/assets/down.png" >
                    <span>5%（相对于上一时段）</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="gov-sub1-top-pie">
              <chart :options="chart1" :theme="chartTheme" auto-resize></chart>
            </div>
          </div>
        </div>
      </div>
      <div>
        <div class="gov-box">
          <div class="gov-title">
            <p>行政中心用电负荷趋势<i class="gl"></i><i class="gl"></i></p>
          </div>
          <chart :options="chart2" :theme="chartTheme" auto-resize></chart>
        </div>
        <div class="gov-box">
            <div class="gov-title">
              <p>行政中心用电量统计<i class="gl"></i><i class="gl"></i></p>
            </div>
            <chart :options="chart3" :theme="chartTheme" auto-resize></chart>
        </div>
        <div class="gov-box">
          <table class="gov-table">
            <thead>
              <tr>
                <th>名次</th>
                <th>单位名称</th>
                <th>耗电量</th>
                <th>与上日同比</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item,key) in agencyelecRank" :key="item.index">
                <td>{{key+1}}</td>
                <td>{{item.name}}</td>
                <td :style="{color:'#04ffd6'}">{{item.lastdata}}</td>
                <td>{{item.rate}}</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div> 
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'governmentA',
  data () {

    return {
      chartTheme: {},
      chart1: {
        color: ['#0024e4','#9d4fff','#4bf7ff','#acfbff','#2ba0ff','#0b4dff'],
        tooltip : {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          show: false,
        },  
        series : [
          {
            name:'访问来源',
            type:'pie',
            radius : ['25%','75%'],
            center: ['50%', '50%'],
            data:[
              {value:435, name:'海宁市统计局'},
              {value:310, name:'海宁市旅游局'},
              {value:274, name:'海宁市信访局'},
              {value:235, name:'海宁市环保局'},
              {value:200, name:'海宁市政法委员会'},
              {value:200, name:'海宁市人们政府办公室'}
            ].sort(function (a, b) { return a.value - b.value; }),
            label: {
              normal: {
                textStyle: {
                  color: '#fff'
                }
              }
            },
            labelLine: {
              normal: {
                lineStyle: {
                  color: '#fff'
                },
                length: 10,
                length2: 60
              }
            }
          }
        ]
      },
      chart2: {
        color: ['#0045de'],
        tooltip : {
          trigger: 'axis',
          axisPointer: {
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          show: false,
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            boundaryGap : false,
            data : ['1:00','1:05','1:10','1:15','1:20','1:25','1:30','1:35','1:40','1:45','1:50','1:55','2:00','2:05'],
          }
        ],
        yAxis : [
          {
            name: '用电负荷（kW）',
            type : 'value',
          }
        ],
        series : [
          {
            name:'用电负荷',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210],
            areaStyle: {
                normal: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgb(0, 69, 222)'
                  }, {
                    offset: 1,
                    color: 'rgb(0, 100, 222)'
                  }])
                }
            },

          }
        ]
      },
      chart3: {
        tooltip : {
          trigger: 'axis',
          axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis : [
          {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis : [
          {
            name: '用电量（kWh）',
            type : 'value',
          }
        ],
        series : [
          {
            name:'用电量',
            type:'bar',
            barWidth: '20%',
            data:[10, 52, 200, 334, 390, 330, 220],
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[
                  {offset: 0, color: '#994dff'},
                  {offset: 1, color: '#0020ed'}
                ]),
              }
            }
          }
        ]
      },
      agencyelecRank: [],
      curentLoad: {load:''},
      yesterdayElecConsum: {consum:''},
      yesterdayWaterConsum: {flow:''},
    }
  },
  mounted: function () {
    this.$http('/vqdisplay/static/HospitalChartTheme.json')
    .then( (response) => {
      this.chartTheme = response.data
    })
    this.getData()
  },
  methods:{
    getData: function () {
      this.$http('/vqdisplay/agency/data')
      .then( response => {
        let _data = response.data.body
        console.log(_data)
        this.curentLoad = _data.curentload
        this.yesterdayElecConsum = _data.yesterdayelecconsum
        this.yesterdayWaterConsum = _data.yesterdaywaterconsum
        
        this.chart1.series[0].data = _data.unitload_pie.series
        this.chart2.xAxis[0].data = _data.govcentreload_trend_line.xAxis
        this.chart2.series[0].data = _data.govcentreload_trend_line.series[0]['用电负荷']

        this.chart3.xAxis[0].data = _data.govcentreelec_trend_bar.xAxis
        this.chart3.series[0].data = _data.govcentreelec_trend_bar.series[0]['用电量']
        
        this.agencyelecRank = _data.agencyelec_rank
        
      })
    },
    selectImg: function(item) {
      if (item) {
        if (item.indexOf('-')>=0) {
          return '/vqdisplay/static/down.png'        
        } else {
          return '/vqdisplay/static/up.png'
        }
      } else {
        return '/vqdisplay/static/down.png'
      }
    }
  }
}
</script>

<style scoped>
  @import '../../../style/government.css';
  .echarts {
    height: 80%;
    width: 100%;
  }
</style>